<?php
include_once("../service/userService.php");
include_once("../util/constant.php");

$userId = $_POST["edit_user_id"];

$fullName = $_POST["userFullname"];
$gender = $_POST["userGender"];
$email = $_POST["userEmail"];

$groups = isset($_POST["selectedPrivilegess"])?$_POST["selectedPrivilegess"]:array();
$result = updateStaff($fullName, $gender, $email,$userId);

if($result){
    unassignStaffFromGroup($userId);
    for($i = 0; $i < count($groups); $i++){
        assignStaffToGroup($userId,$groups[$i]);
    }
	echo "<script>window.location.href = '../admin/user-detail.php?id=".$userId."&action=".EDIT_ACTION."';</script>";
}
else
	echo "<script>window.location.href = '../admin/user-detail.php?action=".NEW_ACTION."';</script>";

?>